<template>
  <div class="smart-city-page">
    <div class="smart-city-content">
      <!-- UE固定尺寸容器 -->
      <div class="ue-container">
        <iframe 
          :src="ueConfig.streamUrl" 
          class="ue-iframe"
          frameborder="0"
          allowfullscreen
        ></iframe>

        <!-- 顶部信息栏 -->
        <div class="top-info-bar">
          <div class="left-tabs">
            <div class="tab-item active">标题1</div>
            <div class="tab-item">标题2</div>
            <div class="tab-item">标题3</div>
          </div>
          <div class="center-title">
            <h1 class="main-title">智慧城市</h1>
          </div>
          <div class="right-info">
            <div class="datetime">{{ currentDateTime }}</div>
            <div class="weather">☁️ 36℃</div>
          </div>
        </div>

        <!-- 左侧数据面板 -->
        <div class="left-panel">
          <!-- 建筑用地规划 -->
          <div class="panel-section">
            <h3 class="section-title">建筑用地规划</h3>
            <div class="circular-chart-container">
              <div class="circular-chart">
                <div class="chart-center">
                  <div class="percentage">54%</div>
                  <div class="label">总建设用地占比</div>
                </div>
              </div>
              <div class="chart-info">
                <div class="info-value">123 <span class="unit">平方公里</span></div>
                <div class="info-label">建筑用地规模</div>
              </div>
            </div>
          </div>

          <!-- 城市用地规划 -->
          <div class="panel-section">
            <h3 class="section-title">城市用地规划</h3>
            <div class="land-use-bars">
              <div class="land-bar-item" v-for="item in landUseData" :key="item.label">
                <span class="land-bar-label">{{ item.label }}</span>
                <div class="land-bar-container">
                  <div class="land-bar-fill" :style="{ width: item.percentage + '%' }"></div>
                </div>
                <span class="land-bar-value">{{ item.percentage }}%</span>
              </div>
            </div>
          </div>

          <!-- 基础资源用量 -->
          <div class="panel-section">
            <h3 class="section-title">基础资源用量</h3>
            <div class="resource-items">
              <div class="resource-item" v-for="item in resourceData" :key="item.label">
                <div class="resource-icon">🏛️</div>
                <div class="resource-info">
                  <div class="resource-value">{{ item.value }}</div>
                  <div class="resource-label">{{ item.label }}</div>
                </div>
              </div>
            </div>
          </div>
        </div>

        <!-- 右侧数据面板 -->
        <div class="right-panel">
          <!-- 人口规划 -->
          <div class="panel-section">
            <h3 class="section-title">人口规划</h3>
            <div class="population-chart">
              <div class="population-circle">
                <div class="population-center">
                  <div class="population-number">123万</div>
                  <div class="population-label">人口总数</div>
                </div>
              </div>
              <div class="population-details">
                <div class="detail-item">
                  <span class="detail-label">XX人口</span>
                  <span class="detail-value">123万</span>
                </div>
                <div class="detail-item">
                  <span class="detail-label">XX人口</span>
                  <span class="detail-value">123万</span>
                </div>
              </div>
            </div>
          </div>

          <!-- 道路规划 -->
          <div class="panel-section">
            <h3 class="section-title">道路规划</h3>
            <div class="road-chart">
              <div class="chart-legend">
                <span class="legend-item">地上道路面积</span>
                <span class="legend-item">地下道路面积</span>
              </div>
              <div class="bar-chart">
                <div class="bar-item" v-for="(item, index) in roadData" :key="index">
                  <div class="bar-wrapper">
                    <div class="bar-top" :style="{ height: item.above + 'px' }"></div>
                    <div class="bar-bottom" :style="{ height: item.below + 'px' }"></div>
                  </div>
                  <div class="bar-text">{{ item.label }}</div>
                </div>
              </div>
            </div>
          </div>

          <!-- 土地规划用地占比 -->
          <div class="panel-section">
            <h3 class="section-title">土地规划用地占比</h3>
            <div class="land-ratio-chart">
              <div class="ratio-item" v-for="item in landRatioData" :key="item.label">
                <div class="ratio-bar">
                  <div class="ratio-fill" :style="{ height: item.percentage + '%' }"></div>
                </div>
                <div class="ratio-info">
                  <div class="ratio-percentage">{{ item.percentage }}%</div>
                  <div class="ratio-value">{{ item.value }} 公顷</div>
                  <div class="ratio-label">{{ item.label }}</div>
                </div>
              </div>
            </div>
          </div>
        </div>

        <!-- 底部导航栏 -->
        <div class="bottom-nav">
          <div class="nav-item" v-for="(nav, index) in navItems" :key="index" :class="{ active: activeNav === index }">
            <div class="nav-icon">{{ nav.icon }}</div>
            <div class="nav-label">{{ nav.label }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from "vue";

// UE配置参数
const ueConfig = ref({
  // UE服务地址
  streamUrl: 'http://127.0.0.1:11193/video.html'
});

// 响应式状态
const currentDateTime = ref('');
const activeNav = ref(0);

// 数据配置
const landUseData = ref([
  { label: '城镇居住', percentage: 90 },
  { label: '农村居住', percentage: 70 },
  { label: '公共设施', percentage: 50 },
  { label: '工业存储', percentage: 30 },
  { label: '绿化广场', percentage: 70 },
  { label: '道路与交通设施', percentage: 50 }
]);

const resourceData = ref([
  { label: '人均公共文化开销', value: '5784' },
  { label: '人均公共体育用地面积', value: '5784' }
]);

const roadData = ref([
  { label: 'AG', above: 60, below: 40 },
  { label: 'BG', above: 50, below: 30 },
  { label: 'CG', above: 70, below: 45 },
  { label: 'DG', above: 40, below: 25 },
  { label: 'EG', above: 65, below: 35 },
  { label: 'FG', above: 75, below: 50 },
  { label: 'GG', above: 55, below: 30 },
  { label: 'HG', above: 80, below: 60 }
]);

const landRatioData = ref([
  { label: 'XX空间用地', percentage: 95, value: '541' },
  { label: 'XX空间用地', percentage: 87, value: '541' },
  { label: 'XX空间用地', percentage: 92, value: '541' }
]);

const navItems = ref([
  { icon: '🏠', label: '综合概况' },
  { icon: '⚙️', label: '设备参数' },
  { icon: '📊', label: '历史数据' },
  { icon: '⚠️', label: '告警信息' }
]);

// 更新时间
const updateDateTime = () => {
  const now = new Date();
  const options = { 
    year: 'numeric', 
    month: '2-digit', 
    day: '2-digit',
    hour: '2-digit',
    minute: '2-digit',
    weekday: 'long'
  };
  currentDateTime.value = now.toLocaleString('zh-CN', options);
};

onMounted(() => {
  console.log('智慧城市页面已加载，UE数据流iframe已就绪');
  console.log('UE配置:', ueConfig.value);
  
  updateDateTime();
  setInterval(updateDateTime, 1000);
});

onUnmounted(() => {
  console.log('智慧城市页面已卸载');
});
</script>

<style scoped>
/* 重置所有可能的margin和padding */
.smart-city-page * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.smart-city-page {
  width: 100%;
  height: 100%;
  background: #e3f2fd;
  color: #333;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  font-family: "Microsoft YaHei", sans-serif;
  overflow: hidden;
}

.smart-city-content {
  width: 100%;
  height: 100%;
  position: relative;
  margin: 0;
  padding: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ue-container {
  width: 100%;
  height: 100%;
  position: relative;
  margin: 0;
  padding: 0;
  max-width: 1920px;
  max-height: 1080px;
}

.ue-iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
  margin: 0;
  padding: 0;
  object-fit: fill;
  /* 强制覆盖iframe样式，消除黑边 */
  transform: scale(1.05);
  transform-origin: center center;
}

/* 顶部信息栏 */
.top-info-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 80px;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 40px;
  z-index: 10;
  border-bottom: 2px solid #00f2fe;
}

.left-tabs {
  display: flex;
  gap: 20px;
}

.tab-item {
  padding: 8px 20px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 20px;
  color: #ffffff;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.tab-item.active,
.tab-item:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: #00f2fe;
  color: #00f2fe;
}

.center-title {
  flex: 1;
  text-align: center;
}

.main-title {
  color: #00f2fe;
  font-size: 32px;
  font-weight: bold;
  margin: 0;
  text-shadow: 0 0 20px #00f2fe;
  letter-spacing: 2px;
}

.right-info {
  display: flex;
  align-items: center;
  gap: 20px;
  color: #00f2fe;
  font-size: 16px;
  font-weight: 500;
}

/* 左右面板通用样式 */
.left-panel, .right-panel {
  position: absolute;
  top: 100px;
  width: 300px;
  height: calc(100% - 130px);
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(0, 242, 254, 0.3);
  border-radius: 8px;
  padding: 15px;
  z-index: 5;
}

.left-panel {
  left: 20px;
  overflow-y: auto;
}

.right-panel {
  right: 20px;
}

.panel-section {
  margin-bottom: 25px;
  min-height: 150px;
}

.section-title {
  color: #00f2fe;
  font-size: 18px;
  font-weight: bold;
  margin: 0 0 15px 0;
  text-align: center;
  border-bottom: 1px solid rgba(0, 242, 254, 0.3);
  padding-bottom: 10px;
}

/* 建筑用地规划 - 圆形图表 */
.circular-chart-container {
  display: flex;
  align-items: center;
  gap: 20px;
}

.circular-chart {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: conic-gradient(#00f2fe 0deg 194deg, rgba(255, 255, 255, 0.2) 194deg 360deg);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.circular-chart::before {
  content: '';
  position: absolute;
  width: 70px;
  height: 70px;
  background: rgba(0, 30, 60, 0.9);
  border-radius: 50%;
}

.chart-center {
  position: relative;
  z-index: 1;
  text-align: center;
}

.percentage {
  color: #00f2fe;
  font-size: 20px;
  font-weight: bold;
}

.label {
  color: #ffffff;
  font-size: 10px;
  margin-top: 2px;
}

.chart-info {
  flex: 1;
}

.info-value {
  color: #00f2fe;
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 5px;
}

.unit {
  font-size: 12px;
  color: #ffffff;
}

.info-label {
  color: #ffffff;
  font-size: 12px;
}

/* 城市用地规划 - 横向条形图 */
.land-use-bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.land-bar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.land-bar-label {
  color: #ffffff;
  font-size: 12px;
  width: 80px;
  flex-shrink: 0;
}

.land-bar-container {
  flex: 1;
  height: 16px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  overflow: hidden;
}

.land-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #00f2fe, #4facfe);
  border-radius: 8px;
  transition: width 0.3s ease;
}

.land-bar-value {
  color: #00f2fe;
  font-size: 12px;
  width: 35px;
  text-align: right;
}

/* 基础资源用量 */
.resource-items {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.resource-item {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 10px;
  background: rgba(0, 242, 254, 0.1);
  border-radius: 8px;
  border: 1px solid rgba(0, 242, 254, 0.2);
}

.resource-icon {
  font-size: 24px;
}

.resource-info {
  flex: 1;
}

.resource-value {
  color: #00f2fe;
  font-size: 18px;
  font-weight: bold;
}

.resource-label {
  color: #ffffff;
  font-size: 12px;
  margin-top: 2px;
}

/* 人口规划 */
.population-chart {
  display: flex;
  align-items: center;
  gap: 20px;
}

.population-circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 3px solid #00f2fe;
  background: rgba(0, 242, 254, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.population-center {
  text-align: center;
}

.population-number {
  color: #00f2fe;
  font-size: 20px;
  font-weight: bold;
}

.population-label {
  color: #ffffff;
  font-size: 10px;
  margin-top: 2px;
}

.population-details {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detail-item {
  display: flex;
  justify-content: space-between;
  padding: 8px;
  background: rgba(0, 242, 254, 0.1);
  border-radius: 4px;
}

.detail-label {
  color: #ffffff;
  font-size: 12px;
}

.detail-value {
  color: #00f2fe;
  font-size: 12px;
  font-weight: bold;
}

/* 道路规划 */
.road-chart {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 150px;
}

.chart-legend {
  display: flex;
  justify-content: center;
  gap: 20px;
  font-size: 10px;
  margin-bottom: 10px;
}

.legend-item {
  color: #ffffff;
  position: relative;
  padding-left: 15px;
}

.legend-item:nth-child(1)::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 8px;
  background: #00f2fe;
  border-radius: 2px;
}

.legend-item:nth-child(2)::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 8px;
  background: #4facfe;
  border-radius: 2px;
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  height: 160px;
  padding: 15px 10px;
  gap: 8px;
}

.bar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  max-width: 30px;
}

.bar-wrapper {
  display: flex;
  flex-direction: column;
  width: 18px;
  margin-bottom: 8px;
}

.bar-top {
  background: #00f2fe;
  border-radius: 2px 2px 0 0;
  min-height: 2px;
}

.bar-bottom {
  background: #4facfe;
  border-radius: 0 0 2px 2px;
  min-height: 2px;
}

.bar-text {
  color: #ffffff;
  font-size: 10px;
  text-align: center;
}

/* 土地规划用地占比 */
.land-ratio-chart {
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  gap: 15px;
}

.ratio-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}

.ratio-bar {
  width: 40px;
  height: 100px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
  margin-bottom: 10px;
}

.ratio-fill {
  position: absolute;
  bottom: 0;
  width: 100%;
  background: linear-gradient(to top, #00f2fe, #4facfe);
  border-radius: 0 0 4px 4px;
  transition: height 0.3s ease;
}

.ratio-info {
  text-align: center;
}

.ratio-percentage {
  color: #00f2fe;
  font-size: 16px;
  font-weight: bold;
}

.ratio-value {
  color: #ffffff;
  font-size: 12px;
  margin: 2px 0;
}

.ratio-label {
  color: #ffffff;
  font-size: 10px;
}

/* 底部导航 */
.bottom-nav {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 40px;
  padding: 20px;
  z-index: 10;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: all 0.3s ease;
}

.nav-item.active .nav-icon {
  background: #00f2fe;
  box-shadow: 0 0 20px #00f2fe;
}

.nav-icon {
  width: 60px;
  height: 60px;
  border: 2px solid #00f2fe;
  border-radius: 50%;
  background: rgba(0, 242, 254, 0.1);
  margin-bottom: 8px;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.nav-label {
  color: #00f2fe;
  font-size: 12px;
  font-weight: 500;
}

/* 响应式设计 */
.ue-container {
  /* 确保容器不会超出父容器 */
  box-sizing: border-box;
}

/* 在小屏幕上保持16:9比例 */
@media (max-width: 1920px) or (max-height: 1080px) {
  .ue-container {
    aspect-ratio: 16/9;
    width: 100%;
    height: 100%;
    max-height: 100%;
  }
}
</style>